#include <QSettings>
#include "linkinfo.h"

LinkInfo* LinkInfo::_instance=NULL;

LinkInfo* LinkInfo::instance()
{
	if (NULL==_instance)
	{
		_instance = new LinkInfo();
	}
	return _instance;
}

LinkInfo::LinkInfo()
{
	//Timer value defination, milliseconds
	interval_wait_bind = 10;
	interval_bind = 5000;
	interval_enquire_link=10000;
	//times wait for enquirelink response
	enquirelink_counter =3;
//	counter=3;
	ClientVersion = 0;

	readSettings();

}

LinkInfo::~LinkInfo()
{
	writeSettings();

}

void LinkInfo::readSettings()
{
	QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, ".");

	QSettings settings("config.ini", QSettings::IniFormat);
	
	settings.beginGroup("LinkInfo");
	localipaddr = settings.value( "localipaddr"			 ).toString();
	localport = settings.value( "localport"			 ).toInt();
	remoteipaddr = settings.value( "remoteipaddr"			 ).toString();
	remoteport = settings.value( "remoteport"			 ).toInt();
	Username = settings.value( "Username"			 ).toString();
	Password = settings.value( "Password"			 ).toString();
	BindMode = settings.value( "BindMode"			 ).toInt();
	ClientVersion = settings.value( "ClientVersion"			 ).toInt();
	settings.endGroup();
	
//	QMessageBox::critical(NULL, QObject::tr("SYSTEM!\n"),ipaddr);
}

void LinkInfo::writeSettings()
{
	QSettings settings("config.ini", QSettings::IniFormat);
	
	settings.beginGroup("LinkInfo");
	settings.setValue("localipaddr", localipaddr);
	settings.setValue("localport", localport);
	settings.setValue("remoteipaddr", remoteipaddr);
	settings.setValue("remoteport", remoteport);
	settings.setValue("Username", Username);
	settings.setValue("Password", Password);
	settings.setValue("BindMode", BindMode);
	settings.setValue("ClientVersion", ClientVersion);
	settings.endGroup();
//	QMessageBox::critical(NULL, QObject::tr("PORT!\n"),"end");
}

